<template>
  <div>
    账号:
    <input type="text" v-model="formdata.username" name="" id="" />
    密码：
    <input type="text" v-model="formdata.password" name="" id="" />
    <button @click="handleSubmit">登陆</button>
  </div>
</template>

<script>
import axios from 'axios'
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      formdata: {
        username: '',
        password: '',
      },
    }
  },
  methods: {
    ...mapMutations(['set_token']),
    async handleSubmit() {
      const res = await axios.post('/api/login', this.formdata)
      console.log('res:', res.data.data.token)
      this.set_token(res.data.data.token)
      this.$router.push('/layout/home')
    },
  },
}
</script>

<style></style>
